#include <adcatch.hpp>
#include <battery.hpp>
#include <settings.hpp>

Battery::Battery()
	: m_Vcc(0)
	, m_VccPrev(0)
	, m_VccFilter(0.1)
	, m_VccScale(0.001669053)
{
}

Battery::~Battery()
{
}

void Battery::Init()
{
}

void Battery::RunImpl(msg_power_s* battery)
{
	if (battery == nullptr)
	{
		return;
	}

	uint16_t adc = 0;

	ADCatch::Instance()->RunImpl(adc, E_ADC1, 0);

	double val = adc * m_VccScale;
	m_Vcc	   = val * m_VccFilter + m_VccPrev * (1.0 - m_VccFilter);
	m_VccPrev  = m_Vcc;

	battery->adc = adc;
	battery->vcc = m_Vcc;
}